package com.hhxy.web;

import com.hhxy.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    //细节：因为在该类中要多次使用BrandService对象所以提升作用域
    BrandService service = new BrandService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、获取BrandService对象
        //2、接收请求参数
        String id = request.getParameter("id");
        //3、BrandService对象完成完成查询
        service.delete(Integer.parseInt(id));
        //4、请求转发到updateBrand.jsp中，让其响应数据
        request.getRequestDispatcher("/SelectAllServlet").forward(request,response);
    }
}
